package com.keyancompany.zhongbaopingtai.adapter;

import android.content.Context;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.model.Task;

import java.util.List;

/**
 * 任务
 */
public class TaskAdapter extends ListAdapter<Task> {

    boolean isMyTeam = false;
    String tagState;

    public TaskAdapter(Context ctx, boolean isMyTeam, List<Task> list) {
        super(list, ctx);
        this.isMyTeam = isMyTeam;
    }

    @Override
    public int getContentViewId() {
        return R.layout.item_task;
    }

    @Override
    public HolderView getHoldView(int position, View contentView, ViewGroup parent) {
        TaskHolder hold = new TaskHolder();
        hold.state = (TextView) contentView.findViewById(R.id.state);
        hold.tasklabel = (TextView) contentView.findViewById(R.id.task_label);
        hold.tasklabel.setVisibility(View.GONE);
        hold.title = (TextView) contentView.findViewById(R.id.task_title);
        hold.taskDis = (TextView) contentView.findViewById(R.id.task_describe);
        hold.fromUser = (TextView) contentView.findViewById(R.id.from_user);

        hold.toUser = (TextView) contentView.findViewById(R.id.to_user);
        hold.groups = (TextView) contentView.findViewById(R.id.groups);
        hold.fromUser = (TextView) contentView.findViewById(R.id.from_user);

        hold.startTime = (TextView) contentView.findViewById(R.id.task_start);
        hold.endTime = (TextView) contentView.findViewById(R.id.task_end);

        return hold;
    }

    @Override
    public void setItemView(int position, HolderView contentView, Task item) {
        TaskHolder hold = (TaskHolder) contentView;

        hold.state.setText(tagState);
        hold.state.setVisibility(View.GONE);
        hold.title.setText(item.getTitle());
        hold.taskDis.setText(Html.fromHtml(item.getTaskDis()));
        hold.fromUser.setText("发布者:" + item.getSendUserName());
        hold.toUser.setText("指派:" + item.getToUserName());
        hold.groups.setText("分组:" + item.getTeamCodeName());
        hold.startTime.setText("开始时间:" + item.getTaskStart());
        hold.endTime.setText("结束时间:" + item.getTaskEnd());
    }


    public class TaskHolder extends HolderView {

        private TextView state;
        private TextView tasklabel;
        private TextView title;
        private TextView taskDis;
        private TextView fromUser;
        private TextView toUser;
        private TextView groups;
        private TextView startTime;
        private TextView endTime;

    }
}
